/**
*****************************************************************************************
*     Copyright(c) 2015, Realtek Semiconductor Corporation. All rights reserved.
*****************************************************************************************
* @file     switch_model.h
* @brief    Head file for switch models.
* @details  Data types and external functions declaration.
* @author   hector_huang
* @date     2020-06-16
* @version  v1.0
* *************************************************************************************
*/
#ifndef _SWITCH_MODEL_H
#define _SIWTCH_MODEL_H

/* Add Includes here */
#include "mesh_api.h"

BEGIN_DECLS

/* switch model msg */
#define MESH_MSG_SWITCH_HEARTBEAT                       0xE05D00
#define MESH_MSG_SWITCH_ADDR_GET                        0xE15D00
#define MESH_MSG_SWITCH_ADDR_STATUS                     0xE25D00
#define MESH_MSG_SWITCH_DATATRANS                       0xE35D00
#define MESH_MSG_SWITCH_RESET                           0xE45D00

/* switch model id */
#define MESH_MODEL_SWITCH                               0x0010005D

typedef struct
{
    uint8_t opcode[ACCESS_OPCODE_SIZE(MESH_MSG_SWITCH_HEARTBEAT)];
    uint8_t mac_addr[6];
} _PACKED_ switch_heartbeat_t;

typedef struct
{
    uint8_t opcode[ACCESS_OPCODE_SIZE(MESH_MSG_SWITCH_ADDR_GET)];
} _PACKED_ switch_addr_get_t;

typedef struct
{
    uint8_t opcode[ACCESS_OPCODE_SIZE(MESH_MSG_SWITCH_ADDR_STATUS)];
    uint8_t addr[6];
} _PACKED_ switch_addr_status_t;

typedef struct
{
    uint8_t opcode[ACCESS_OPCODE_SIZE(MESH_MSG_SWITCH_DATATRANS)];
    uint8_t data[ACCESS_PAYLOAD_MAX_SIZE - ACCESS_OPCODE_SIZE(MESH_MSG_SWITCH_DATATRANS)];
} _PACKED_ switch_datatrans_t;

typedef struct
{
    uint8_t opcode[ACCESS_OPCODE_SIZE(MESH_MSG_SWITCH_RESET)];
    uint8_t mac_addr[6];
} _PACKED_ switch_reset_t;

/* switch callback data */
#define SWITCH_MODEL_HEARTBEAT                               0 //!< @ref switch_model_heartbeat_t
#define SWITCH_MODEL_ADDR_GET                                1 //!< @ref switch_model_addr_get_t
#define SWITCH_MODEL_ADDR_STATUS                             2 //!< @ref switch_model_addr_status_t
#define SWITCH_MODEL_DATATRANS                               3 //!< @ref switch_model_datatrans_t

typedef struct
{
    uint16_t src;
    uint8_t mac_addr[6];
} switch_model_heartbeat_t;

typedef struct
{
    uint16_t src;
    uint8_t addr[6];
} switch_model_addr_get_t;

typedef struct
{
    uint16_t src;
    uint8_t addr[6];
} switch_model_addr_status_t;

typedef struct
{
    uint16_t src;
    uint8_t *pdata;
    uint16_t data_len;
} switch_model_datatrans_t;

/* switch model functions */
bool switch_model_reg(uint8_t element_index, mesh_model_info_p pmodel_info);

mesh_msg_send_cause_t switch_heartbeat(const mesh_model_info_p pmodel_info, uint16_t dst,
                                       uint16_t app_key_index, uint8_t mac_addr[6]);
mesh_msg_send_cause_t switch_addr_get(const mesh_model_info_p pmodel_info, uint16_t dst,
                                      uint16_t app_key_index);
mesh_msg_send_cause_t switch_datatrans(const mesh_model_info_p pmodel_info, uint16_t dst,
                                       uint16_t app_key_index, const uint8_t *pdata, uint16_t len);
mesh_msg_send_cause_t switch_reset(const mesh_model_info_p pmodel_info, uint16_t dst,
                                   uint16_t app_key_index, uint8_t mac_addr[6]);


END_DECLS

#endif /* _SWITCH_MODEL_H */
